<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix='sec' uri='http://www.springframework.org/security/tags'%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript" src="scripts/boot.js"></script>
</head>
<body style="border: 0px; margin: 0px; padding: 0px;width: 100%;height: 100%">
<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
    <table style="width:100%;">
        <tr>
            <td style="width:100%;">
                <span style="margin-left:10px;">用户名称(模糊)：</span><input id="s_name" class="mini-textbox" emptyText="用户名称(模糊)" style="width:150px;margin-right:10px;" />
                <span style="margin-left:42px;">部门(精确)：</span>
                <div id="s_depts" class="mini-combobox" style="width:150px;margin-left:-5px;"  popupWidth="165" textField="keyValue" valueField="keyName" 
				    url="dictionary_key_val_view.do?typeName=DEPT_TYPE" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="部门(精确)" field="keyValue"></div>
				    </div>
				</div>
				<span style="margin-left:68px;">组(精确)：</span>
				<div id="s_groups" class="mini-combobox" style="width:150px;margin-left:-5px;"  popupWidth="165" textField="name" valueField="id" 
				    url="user_group_view.do" multiSelect="true"  showClose="true" oncloseclick="onCloseClick" >     
				    <div property="columns">
				        <div header="组(精确)" field="name"></div>
				    </div>
				</div>
			</td>
			<td style="white-space:nowrap;">
               	<a class="mini-button" iconCls="icon-search" onclick="search()">查询</a>
           	</td>
		</tr>
    </table>           
</div>
	<div class="mini-toolbar" style="border-bottom:0;padding:0px;">
	    <table style="width:100%;">
	        <tr>
		        <td style="width:100%;">
		        <sec:authorize url='/medical_archival_add.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="add()">增加员工档案信息</a>
	            </sec:authorize>
	            <sec:authorize url='/medical_archival_edit.do'>
	                <a class="mini-button" iconCls="icon-add" onclick="edit()">完善员工档案信息</a>
	            </sec:authorize>
	            <sec:authorize url='/meidcal_archival_del.do'>
	                <a class="mini-button" iconCls="icon-remove" onclick="remove()">批量删除档案信息</a>  
	            </sec:authorize>     
	            </td>
	        </tr>
	    </table>           
	</div>
	<div class="mini-fit" >
	<div id="datagrid1" class="mini-datagrid " idField="id" pageSize="20"
		url="medical_archival_view.do" style="width:100%;height:100%;" allowCellSelect="true" multiSelect="true">
		<div property="columns">
			<div type="indexcolumn" headerAlign="center">#</div>
			<div type="checkcolumn" headerAlign="center"></div>
			<div field="name" width="100" headerAlign="center" align="center">姓名</div>
			<div field="genderName" width="100" headerAlign="center" align="center">性别</div>
			<div field="idCardNum" width="100" headerAlign="center" align="center">身份证号</div>
			<div field="mobile" width="120" headerAlign="center" align="center">电话</div>
			<div field="contractNum" width="80" headerAlign="center" align="center">合同编号</div>
			<div field="entryTime" width="80" headerAlign="center" dateFormat="yyyy-MM-dd" allowSort="true" align="center">入职时间</div>
			<div width="100" headerAlign="center" renderer="onActionRenderer" align="center">相关操作</div>
		</div>
	</div>
	</div>
<script type="text/javascript">
	mini.parse();
	var grid = mini.get("datagrid1");
	grid.load();
	//查询
	function search() {
	    var name = mini.get("s_name").getValue();
	    var deptType = mini.get("s_depts").getValue();
	    var groupIds = mini.get("s_groups").getValue();
	    grid.load({ name: name,
	    	deptType: deptType,
	    	groupIds: groupIds
	    });
	}
	
	//添加
	function add() {
	    mini.open({
	        url: "medical_archival_add.do",
	        allowResize:false,
	        title: "新增员工档案信息", width: 450, height: 420,
	        onload: function () {
	        	var iframe = this.getIFrameEl();
	            $.post("archival_file_type_size.do",{},function(text){
	            	if(text){
	     	            var data = { action: "new",fileType:text.fileType,fileSize:text.fileSize};
	     	            iframe.contentWindow.SetData(data);
	            	}
	            }, "json");
	        },
	        ondestroy: function (action) {
	        	if(action == 'succ'){
	        		mini.showMessageBox({
	                    title: "提示",
	                    showModal:false,
	                    iconCls: "mini-messagebox-info",
	                    message: "保存成功！",
	                    timeout: 3000,
	                    x: 'right',
	                    y: 'bottom'
	                });
		            grid.reload();
	        	}
	        }
	    });
	}
	
	//修改
	function edit() {
	    var row = grid.getSelecteds();
	    if (row.length == 1) {
	        mini.open({
	            url: "medical_archival_edit.do",
	            allowResize:false,
	            title: "完善员工档案信息", width: 450, height: 460,
	            onload: function () {
	                var iframe = this.getIFrameEl();
	                var data = { action: "edit",row:row[0] };
	                iframe.contentWindow.SetData(data);
	            },
	            ondestroy: function (action) {
	            	if(action == 'succ'){
	            		mini.showMessageBox({
	                        title: "提示",
	                        showModal:false,
	                        iconCls: "mini-messagebox-info",
	                        message: "修改成功！",
	                        timeout: 3000,
	                        x: 'right',
	                        y: 'bottom'
	                    });
	                	grid.reload();
	            	}
	            }
	        });
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
	
	//删除
	function remove() {
		var archivalId = '';
	    var rows = grid.getSelecteds();
	    if (rows.length > 0) {
	    	mini.confirm("确定删除选中记录？", "删除",
               function (action) {
	    			if(action == 'ok'){
	    				var ids = [];
	    	            for (var i = 0, l = rows.length; i < l; i++) {
	    	                var r = rows[i];
	    	                ids.push(r.id);
	    	            }
	    	            archivalId = ids.join(',');
	    				$.post('meidcal_archival_del.do', {id: archivalId}, function(data){
	    					if(data.success){
		    					mini.showMessageBox({
				                    title: "提示",
				                    showModal:false,
				                    iconCls: "mini-messagebox-info",
				                    message: "删除成功！",
				                    timeout: 3000,
				                    x: 'right',
				                    y: 'bottom',
				                });
	    						grid.load();
	    					}else{
	    						mini.alert("id不能为空，删除失败！");
	    					}
	   					}, "json");
	    			}
            	}
	    	);
	    } else {
	    	mini.alert("请选中一条记录");
	    }
	}
	
	function onActionRenderer(e) {
		var s = '';
		if(null != e.row.archivesUrl && "" != e.row.archivesUrl){
		     s = '<a class="New_Button" href="javascript:download()">'+'下载附件'+'</a> ';
		}
	    return s;
	}
	
	function download(){
		var row = grid.getSelected();
		if(row.archivesUrl){
			$.post("archival_is_exists.do",{id:row.id},function(data){
				if(data.success){
					location.href = "medical_archival_download.do?id="+row.id;
				}else{
					mini.alert("附件不存在,请联系管理员!");
				}
			}, "json");
		}else{
			mini.alert("未上传相关附件");
		}
	}
	
	function onCloseClick(e) {
        var obj = e.sender;
        obj.setText("");
        obj.setValue("");
    }
</script>
</body>
</html>